/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.network;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
import src.engine.PICAIULuaScript;

/**
 *
 * @author Owner
 */
public class PICAIUAIScripts {

  protected static ArrayList<PICAIULuaScript> gunnerScripts = new ArrayList<PICAIULuaScript>();
  protected static ArrayList<PICAIULuaScript> tankScripts = new ArrayList<PICAIULuaScript>();
  protected static ArrayList<PICAIULuaScript> rocketScripts = new ArrayList<PICAIULuaScript>();
  public static int count;
  
  public static void init() {
    if (PICAIUServer.VERBOSE) {
      System.out.println("Loading AI scripts...");
    }

    File[] files = new File("scripts/").listFiles();
    for (File f : files) {
      
      String scriptIn = "";
      try {
        Scanner sc = new Scanner(f);
        while (sc.hasNextLine()) {
          scriptIn += sc.nextLine();
        }
        PICAIULuaScript script = new PICAIULuaScript(scriptIn);
        TypeSetter type = new TypeSetter();
        script.runFunction("setType", type);
        if (type.getType().equals("gunner")) {
          gunnerScripts.add(script);
          if (PICAIUServer.VERBOSE) {
            System.out.println("loaded " + f.getName());
          }
          count++;
        } else if (type.getType().equals("tank")) {
          tankScripts.add(script);
          if (PICAIUServer.VERBOSE) {
            System.out.println("loaded " + f.getName());
          }
          count++;
        } else if (type.getType().equals("rocketeer")) {
          rocketScripts.add(script);
          if (PICAIUServer.VERBOSE) {
            System.out.println("loaded " + f.getName());
          }
          count++;
        }
      } catch (Exception e) {
      }

    }
    if (PICAIUServer.VERBOSE) {
      System.out.println("Loaded (" + count + ") AI Scripts.");
    }
  }
}

class TypeSetter {

  String type = "";

  public String getType() {
    return type;
  }

  public void setType(String t) {
    type = t;
  }
}
